<%--
  author: winkyle
  date: 2018/11/25
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html lang="en">
<head>
    <!-- jsp文件头和头部 -->
    <%@ include file="../base/top.jsp"%>
</head>
<body class="no-skin">
<!-- /section:basics/navbar.layout -->
<div class="main-container" id="main-container">
    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <div class="hr hr-18 dotted hr-double"></div>
                <div class="row">
                    <div class="col-xs-12">

                        <div class="col-xs-10 col-xs-offset-1">
                            <p style="margin-top: 35px; font-size: 24px; text-align: center; font-family: 'Microsoft Yahei', arial, Tahoma, sans-serif;">
                                ${taskInfo.taskName}
                            </p>
                            <p style="margin-top: 20px; font-size: 17px; text-indent:2em; text-align: justify; font-family: 宋体;">
                                ${taskInfo.taskDescription}
                            </p>
                            <p style="margin-top: 15px; font-size: 15px; text-align: right; font-family: 宋体;">
                                任务期限：<fmt:formatDate value="${taskInfo.taskStartTime}" pattern="yyyy/MM/dd HH:mm"/> ～ <fmt:formatDate value="${taskInfo.taskEndTime}" pattern="yyyy/MM/dd HH:mm"/>
                            </p>
                        </div>
                        <div class="col-xs-12" style="text-align: center">
                            <div style="margin-top: 30px">
                                <img id = "img"
                                     width="70px"></div>
                            <div style="margin-top: 5px;">
                                <a class="btn btn-link" href="${assignmentFile.assignmentAddress}" download="${assignmentFile.assignmentName}${assignmentFile.fileType}"
                                   style="font-size: 17px;  font-family: 宋体; background-repeat: no-repeat;">
                                    ${assignmentFile.assignmentName}
                                </a>
                            </div>
                            <div class="btn btn-sm btn-primary" id="upload" style="margin-top: 30px">提交</div>
                        </div>
                        <div class="col-xs-12" style="position: fixed; bottom: 0; text-align: left; font-size: 10px">
                            <p>注：每次提交将覆盖上一次提交</p>
                            <p style="text-indent: 2em">老师评阅过后将无法再次提交</p>
                        </div>

                    </div>
                    <!-- /.col -->
                </div>
                <!-- /.row -->
            </div>
            <!-- /.page-content -->
        </div>
    </div>

    <!-- /.main-content -->

    <form id="uploadForm">
        <input type="file" id="file" name="file"
               style="filter:alpha(opacity=0);opacity:0;width: 0;height: 0;"/>
    </form>

</div>
<!-- /.main-container -->
<!-- basic scripts -->
<!-- 页面底部js¨ -->
<%@ include file="../base/foot.jsp"%>

<script type="text/javascript">
    console.log("${assignmentFile}");
    $(document).ready(function () {
        $("#img").attr("src",getImageIcon("${(assignmentFile==null)?null:assignmentFile.fileType}"));
    });

    $("#upload").click(function () {
        //触发 文件选择的click事件
        $("#file").trigger("click");
    });
    $("#file").change(function () {
            var form = new FormData(document.getElementById("uploadForm"));
            if(${assignmentFile!=null&&!''.equals(assignmentFile)}){
                if(${assignmentFile.assignmentState>0}){
                    prompt_alert("warning","该文档已被老师下载，不可重新上传");
                }else{
                    form.append("projectId","${assignmentFile.projectId}");
                    form.append("taskId","${assignmentFile.taskId}");
                    form.append("stageId","${assignmentFile.stageId}");
                    form.append("taskType","${taskInfo.taskType}");
                    form.append("assignmentId","${assignmentFile.assignmentId}");
                }
            }else{
                alert(${taskInfo.taskType});
                form.append("taskId","${taskInfo.taskId}");
                form.append("projectId","");
                form.append("taskType",${taskInfo.taskType});
                form.append("stageId","");
                form.append("teachCourseId","${taskInfo.teachCourseId}");
                form.append("assignmentId","${assignmentFile.assignmentId}");
            }

            $.ajax({
                url:"assignment/uploadTaskAssignment",
                type:"post",
                data:form,
                processData:false,
                contentType:false,
                success:function(data){
                    if(data["success"]==true){
                        prompt_alert('success',"上传成功",0);
                    }else{
                        prompt_alert('error',"上传失败",0);
                    }
                },
                error:function (){
                    prompt_alert('error',"失败！",0);
                    reloadDataTable();
                },
            });
        }
    );
</script>
</body>
</html>
